//
//  UtilCore.swift
//  testZD
//
//  Created by 湛亚磊 on 2020/9/25.
//  Copyright © 2020 湛亚磊. All rights reserved.
//

import UIKit
/// 本模块的名称， 本模块的storyboard 名称必须 与模块名称相同 ,静态资源的加载回用到
let modularName = "LLZBaseTools"
public class UtilCore: NSObject {
    /// 提示错误码
    static private var msg:Dictionary<Int,(msgcode:Int,msgtitle:String,msginfo:String)> = [:]
    public var baseUrl:String = ""
    /// 字体类型
    public var fontName:String = "Helvetica"
    public static var sharedInstance : UtilCore {
        struct Static {
            static let instance : UtilCore = UtilCore()
        }
        let utilCore = Static.instance
        utilCore.update()
        return utilCore
    }
    ///用于提供弹出信息
    static public var alertmsg:Dictionary<Int,(msgcode:Int,msgtitle:String,msginfo:String)>{
        get{
            for dict  in UtilCore.msg {
                alert_msg[dict.0] = dict.1
            }
            return alert_msg
        }
        set (newValue){
            UtilCore.msg = newValue
        }
    }
    func update() -> Void {
        guard let path = Bundle.main.path(forResource: "UtilCore", ofType: "plist") else {
            return
        }
        guard let dict = NSDictionary(contentsOfFile:path) else {
            return
        }
        if let baseurl = dict["baseurl"] as? String {
            self.baseUrl = baseurl
        }
        if let fontname = dict["fontname"] as? String {
            self.fontName = fontname
        }
        
    }
    
    ///供其他模块使用
    public static var bundle:Bundle? {
        get {
            guard let bundleURL = Bundle(for: UtilCore.self).url(forResource: modularName, withExtension: "bundle") else {
                return nil
            }
            guard let bundle = Bundle(url: bundleURL) else {
                return nil
            }
            return bundle
        }
    }
}



var  alert_msg :Dictionary<Int,(msgcode:Int,msgtitle:String,msginfo:String)>
    = [
        100001111 : (msgcode:100001000,msgtitle:"网络错误",msginfo:"在生产模式时吧系统错误码为1的改为提示")
]
